/*
 * @lc app=leetcode.cn id=125 lang=cpp
 *
 * [125] 验证回文串
 */

// @lc code=start
class Solution {
public:
    bool isPalindrome(string s) {
        int l = 0, r = s.size();

        while (l < r) {
            s[l] = tolower(s[l]);
            s[r] = tolower(s[r]);

            if ((s[l] < 'a' || s[l] > 'z') && 
                (s[l] < '0' || s[l] > '9')) {
                l++;
                continue;
            }
            
            if ((s[r] < 'a' || s[r] > 'z') &&
                (s[r] < '0' || s[r] > '9')) {
                r--;
                continue;
            }

            if (s[l] != s[r])
                return false;

            l++;
            r--;
        }

        return true;
    }
};
// @lc code=end

